// 微服务端到端测试配置文件
export const microservicesConfig = {
  // API网关地址
  apiGateway: 'http://localhost:8081',
  
  // 各个微服务地址（用于直接测试）
  services: {
    userService: 'http://localhost:8082',
    courseService: 'http://localhost:8083', 
    exerciseService: 'http://localhost:8084',
    progressService: 'http://localhost:8085'
  },
  
  // 测试数据配置
  testData: {
    // 测试用户
    users: {
      teacher: {
        account: 'teacher_e2e_001',
        password: 'Teacher@123',
        name: '端到端测试教师',
        email: 'teacher.e2e@coursehub.com',
        role: 'Teacher'
      },
      student: {
        account: 'student_e2e_001', 
        password: 'Student@123',
        name: '端到端测试学生',
        email: 'student.e2e@coursehub.com',
        role: 'Student'
      },
      admin: {
        account: 'admin_e2e_001',
        password: 'Admin@123',
        name: '端到端测试管理员',
        email: 'admin.e2e@coursehub.com',
        role: 'Admin'
      }
    },
    
    // 测试课程
    courses: {
      softwareEngineering: {
        courseId: 'SE_E2E_2024',
        courseName: '软件工程E2E测试课程',
        description: '用于端到端测试的软件工程课程',
        teachingGoal: '掌握软件工程基本概念和端到端测试方法',
        examinationMethod: '平时作业40% + 项目30% + 期末考试30%',
        credits: 3
      }
    },
    
    // 测试班级
    classes: {
      class1: {
        classId: 'SE_E2E_CLASS_001',
        className: '软工E2E测试班级',
        maxStudents: 50
      }
    },
    
    // 测试练习
    exercises: {
      exercise1: {
        name: 'E2E测试练习1',
        description: '第一个端到端测试练习',
        totalScore: 100,
        duration: 60, // 分钟
        questions: [
          {
            type: 'single_choice',
            content: '软件工程的主要目标是什么？',
            options: [
              '提高开发速度',
              '降低开发成本',
              '提高软件质量和可维护性',
              '增加功能数量'
            ],
            answer: 'C',
            score: 25
          }
        ]
      }
    }
  },
  
  // API端点配置
  endpoints: {
    auth: {
      login: '/api/users/login',
      register: '/api/users/register',
      logout: '/api/users/logout',
      profile: '/api/users/profile'
    },
    courses: {
      list: '/api/courses',
      create: '/api/courses',
      detail: '/api/courses/{courseId}',
      join: '/api/courses/{courseId}/join',
      materials: '/api/courses/{courseId}/materials'
    },
    exercises: {
      list: '/api/exercises',
      create: '/api/exercises',
      submit: '/api/exercises/{exerciseId}/submit',
      grade: '/api/exercises/{exerciseId}/grade'
    },
    progress: {
      learning: '/api/progress/learning/{userId}/{courseId}',
      statistics: '/api/progress/statistics/{userId}/{courseId}',
      records: '/api/records/activities'
    }
  },
  
  // 测试环境设置
  environment: {
    // 等待时间配置
    timeouts: {
      short: 1000,
      medium: 3000,
      long: 10000,
      veryLong: 30000
    },
    
    // 重试配置
    retries: {
      api: 3,
      ui: 2
    }
  }
}

// 工具函数
export const testUtils = {
  // 生成随机字符串
  generateRandomString: (length = 8) => {
    const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    let result = ''
    for (let i = 0; i < length; i++) {
      result += chars.charAt(Math.floor(Math.random() * chars.length))
    }
    return result
  },
  
  // 生成测试用户数据
  generateTestUser: (role = 'Student') => {
    const randomSuffix = testUtils.generateRandomString(6)
    return {
      account: `${role.toLowerCase()}_${randomSuffix}`,
      password: `${role}@123`,
      name: `测试${role}_${randomSuffix}`,
      email: `${role.toLowerCase()}.${randomSuffix}@test.com`,
      role: role
    }
  },
  
  // 格式化日期时间
  formatDateTime: (date = new Date()) => {
    return date.toISOString().slice(0, 16)
  },
  
  // 获取未来日期
  getFutureDate: (daysFromNow = 7) => {
    const date = new Date()
    date.setDate(date.getDate() + daysFromNow)
    return testUtils.formatDateTime(date)
  }
}
